;(function () {
  new Vue({
    el: '#processMange',
    data: {
      data: [],
      createData: []
    },
    methods: {
      newAdd () {
        if(this.data.length >= 10){
          hl.toast('新增场地最多只能10个')
          return false
        }

        this.createData.push({
          "module_code":"ZUKN",
          "config_name": "ZK_SPACE_CONFIG_TYPE",
          "value": ''
        })
      },
      newPost (i) {
        hlhttp.post({
          url: 'configure/tenant_dict_config',
          data: {
            "module_code": "ZUKN",
            "config_name": "ZK_SPACE_CONFIG_TYPE",
            'dict_name': this.createData[i].value,
            'dict_value': this.createData[i].value,
            'dict_display_name': '#',
            'dict_property': '#',
            'default_flag': 'N',
            'config_type': 'BASE_VALUE'
          },
          success: () => {
            hl.toast('创建成功')
            this.createData.splice(i, 1)
            this.getData()
          }
        })
      },
      newPutFlag (i) {
        this.data[i].flag = true;
      },
      newPut (i) {
        hlhttp.put({
          url: 'configure/tenant_dict_config',
          data: {
            "module_code":"ZUKN",
            "config_name":"ZK_SPACE_CONFIG_TYPE",
            "dict_code": this.data[i].dictCode,
            'dict_name':  this.data[i].dictName,
            "dict_value": this.data[i].dictName,
            'dict_display_name': '#',
            'dict_property': '#',
            'default_flag': 'N',
            'config_type': 'BASE_VALUE'
          },
          success: () => {
            hl.toast('编辑成功')
            this.data[i].flag = false;
          }
        })
      },
      deldict (i) {
        hlhttp.delete({
          url: 'configure/tenant_dict_config?module_code=ZUKN&config_name=ZK_SPACE_CONFIG_TYPE&dict_code='+this.data[i].dictCode,
          success: () => {
            hl.toast('删除成功')
            this.getData()
          }
        })
      },
      enabledict (i) {
        hlhttp.put({
          url: 'configure/tenant_dict_config/enable_and_disable',
          data: {
            "module_code":"ZUKN",
            "config_name":"ZK_SPACE_CONFIG_TYPE",
            "dict_code": this.data[i].dictCode,
            'status': 'Y'
          },
          success: () => {
            hl.toast('启用成功')
            this.getData()
          }
        })
      },
      disabledict (i) {
        hlhttp.put({
          url: 'configure/tenant_dict_config/enable_and_disable',
          data: {
            "module_code":"ZUKN",
            "config_name":"ZK_SPACE_CONFIG_TYPE",
            "dict_code": this.data[i].dictCode,
            'status': 'N'
          },
          success: () => {
            hl.toast('停用成功')
            this.getData()
          }
        })
      },
      removeDom (i) {
        this.createData.splice(i, 1)
      },
      getData () {
        hlhttp.get({
          url: 'configure/dict',
          data: {module_code: 'ZUKN', config_name: 'ZK_SPACE_CONFIG_TYPE', parent_dict_code: '#' , key: '#'},
          success: res => {
            res.map(item => {
              item.flag = false;
            })
            this.data = res;
          }
        })
      }
    },
    mounted () {
      this.getData()
    }
  })
} ())
